<?php
/**
 * Class descript.
 * User: chan
 * Date: 2017/10/20 11:22
 */

namespace app\api\controller;
use app\api\service\Nearby;
use app\api\model\Member as MemberModel;
class Test extends Base
{
    //检查权限作用域
    protected $beforeActionList  = [
        'checkPrimaryScope' => [
            'only' => 'test,getUserInfoByToken'
        ],
    ];
    public function test()
    {
        //验证请求参数方式
        //(new LoginValidate())->checkParam();

        //通过权限获取用户信息
        // var_dump($this->user);
    }

    /**
     * 生成token （上线后需要关闭测试方法)
     * @return \think\response\Json
     *
     */

    public function generateToken()
    {
        $user =  MemberModel::getByUID($this->requestData['userId']);
        $user['uid']= $user['id'];
        $user['userId']= $user['id'];
        $Oauth2 = new \app\api\service\Oauth2();
        return json($Oauth2::generateToken($user));
    }

    /**
     * 获取用户信息 （上线后需要关闭测试方法)
     *
     */
    public function getUserInfoByToken()
    {
        $access_token = $this->requestData['access_token'];
        try{
            $Oauth2 = new \app\api\service\Oauth2();
            return json($Oauth2->getUserInfoByToken($access_token));
            //权限控制（群主有封禁用户服务能力）
        }catch (Exception $e){
            $returnData = json_encode([
                'data' => array(),
                'code' => -1,
                'message' => $e->getMessage(),
                'errorCode' => $e->errorCode
            ]);
            exit($returnData);
        }
    }
}




















